﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;

namespace DanhMuc
{
    class HocVanInfo
    {
        private string _HocVanID;

        public string HocVanID
        {
            get { return _HocVanID; }
            set { _HocVanID = value; }
        }

        private string _TenHocVan;

        public string TenHocVan
        {
            get { return _TenHocVan; }
            set { _TenHocVan = value; }
        }

        private bool _Active;

        public bool Active
        {
            get { return _Active; }
            set { _Active = value; }
        }
    }

    class HocVanCtr
    {
        string strCnn = DBClass_FANIT82.GetConnectString();

        public void Insert(HocVanInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@HocVanID", Item.HocVanID),
                new SqlParameter("@TenHocVan", Item.TenHocVan == null ? (object)DBNull.Value:Item.TenHocVan),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_HocVan_Insert", Para);
        }

        public void Update(HocVanInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@HocVanID", Item.HocVanID),
                new SqlParameter("@TenHocVan", Item.TenHocVan == null ? (object)DBNull.Value:Item.TenHocVan),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_HocVan_Update", Para);
        }

        public void Delete(string strHocVanID)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@HocVanID", strHocVanID),
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_HocVan_Delete", Para);
        }

        public DataTable GetList()
        {
            DataSet Ds = SqlHelper.ExecuteDataset(strCnn, CommandType.StoredProcedure, "D_HocVan_GetList");
            return Ds.Tables[0];
        }

        public HocVanInfo GetByID(string strHocVanID)
        {
            SqlDataReader dtr = SqlHelper.ExecuteReader(strCnn, CommandType.StoredProcedure, "D_HocVan_Get", new SqlParameter("HocVanID", strHocVanID));
            HocVanInfo ObjHocVan = null;
            while (dtr.Read())
            {
                ObjHocVan = new HocVanInfo();
                ObjHocVan.HocVanID = dtr["HocVanID"].ToString();
                ObjHocVan.TenHocVan = dtr["TenHocVan"].ToString();
                ObjHocVan.Active = (bool)dtr["Active"];
            }
            return ObjHocVan;
        }
    }
}
